package br.com.edumobi.adapters;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import br.com.edumobi.R;
import br.com.edumobi.dados.modelos.Classificacao;

public class ListaClassificacoesAdapter extends BaseAdapter {

    private List<Classificacao> classificacoes;

    public ListaClassificacoesAdapter(List<Classificacao> classificacoes) {
        this.classificacoes = classificacoes;
    }

    @Override
    public int getCount() {
        return classificacoes.size();
    }

    @Override
    public Object getItem(int position) {
        return classificacoes.get(position);
    }

    @Override
    public long getItemId(int position) {
        return classificacoes.get(position).id;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Classificacao classificacao = classificacoes.get(position);

        ViewHolder holder;

        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_lista_classificacoes, null);

            holder = new ViewHolder();

            holder.textViewItemListaClassificacaoNome = (TextView) convertView.findViewById(R.id.textViewItemListaClassificacaoNome);
            holder.textViewItemListaClassificacaoDescricao = (TextView) convertView.findViewById(R.id.textViewItemListaClassificacaoDescricao);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.textViewItemListaClassificacaoNome.setText(classificacao.nome);
        holder.textViewItemListaClassificacaoDescricao.setText(classificacao.descricao);

        return convertView;
    }

    private class ViewHolder {
        TextView textViewItemListaClassificacaoNome;
        TextView textViewItemListaClassificacaoDescricao;
    }
}